#################################################
# ReadMe File: Parties, Interest Groups, and Class Influence
#  
# Author(s):  Matt Grossmann, William Isaac, Zuhaib Mahmood
# Updated:	  01.24.2020
#
################################################

This folder contains scripts and functions to replicate "Parties, Interest Groups, and Class Influence". Dataverse required (or seemed to require) that all files be in a single directory, which is why there's so many files in one place. 

The following scripts should exist in the SAME directory. I've nested some of them for aesthetic reasons to organize, but all should be in the same directory:
	- 0_dataprep.R
	- 1_main_models.R
		- 1_models_partysupport.R
		- 2_models_outcomes.R
		- 3_post_partysupport.R
		- 4_post_outcomes.R
	- 2_descriptives.R
	- PartIG_uncorr.R

The following files should exist in the SAME directory as the scripts: 
	- full_gsd_with_latent_weights_4317_revised.csv
	- ReadMe.txt (not used in analysis)

This ReadMe file will provide instructions for replication, as well as detailed explanations for the structure of the replication file for those reading the source code. At the end of the file, it provides a readout of sessionInfo() which details the versions of R (and its associated packages) which were used to compile the final version of these materials.

Replication scripts for appendices are available upon request. 

###########
#Instructions for replication
###########

Open "PartIG_uncorr.R". Select all lines and run the script. It will create output directories.

The file should not require any user input, as long as it is opened directly from the replication directory. Note that this directory should have ALL files in a single place.

The script can also be run via Shell commands for users who prefer to call "Rscript" from their Terminal.

### Notes

Expected warning messages include: 

	(1) various "save" messages from GGplot
	(2) "unknown parameters" message from GGplot during descriptive statistics visualization step

Warning messages of interest, but not necessarily fatal, include:

	(1) A warning stating that you are "overwriting" a previous run. This occurs when any OUTPUT folder that is attempting to be created currently exists, indicating that you might (but not necessarily) have already run the script.This warning simply notes that the script will overwrite previous runs by default. 

Error messages from the main replication script:

	(1) A "stopifnot()" command if, for some reason, the script does not detect a required directory. 
	(2) Errors finding directories. This will happen if you try to re-organize the replication files without changing the corresponding directory-setting code. 

###########
#Explanation of scripts
###########

The following is a more detailed explanation of the workhorse scripts within the ~/SCRIPTS directory. This is intended to guide the process reviewing, debugging, or re-purposing the underlying scripts and functions. It is not intended to provide a comprehensive line-by-line reading of each script. 

Scripts that run post-estimation usually declare functions at the start of the script. 

0_dataprep.R

	This file prepares the underlying replication data based on the source file provided in directory ~/SOURCE.

	It prepares the different splits used in robustness checks--including periods of Democratic and Republican control in congress and the Presidency; the three issue areas (Social=NE; Economic=Econ; Foreign=FP); and the time windows. 

1_main_models.R

	This script runs the primary models of interest in the paper. It draws on scripts in the eponymous directory "/1_main_models" to estimate the models with outputs in LaTex format and to run post-estimation on the models to generate predicted probabilities as well as parameter stability plots. 

	The corresponding directory, "/1_main_models", has a total of four (4) scripts to estimate and visualize models on both policy preferences and policy outcomes.

2_descriptives.R

	This script generates a table of descriptive statistics (in LaTex) and a figure containing distributions for the main variables of interest.

#########
#Session information for R at final compilation of replication materials
#########

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] reshape2_1.4.3  margins_0.3.23  weights_1.0     mice_3.6.0     
 [5] gdata_2.18.0    Hmisc_4.3-0     Formula_1.2-3   survival_3.1-8 
 [9] lattice_0.20-38 xtable_1.8-4    gridExtra_2.3   texreg_1.36.23 
[13] stargazer_5.2.2 dplyr_0.8.3     plyr_1.8.4      magrittr_1.5   
[17] ggplot2_3.2.1  

loaded via a namespace (and not attached):
 [1] mitml_0.3-7         Rcpp_1.0.2          tidyr_1.0.0        
 [4] gtools_3.8.1        assertthat_0.2.1    zeallot_0.1.0      
 [7] digest_0.6.21       pan_1.6             R6_2.4.0           
[10] backports_1.1.5     acepack_1.4.1       jomo_2.6-9         
[13] pillar_1.4.2        rlang_0.4.0         lazyeval_0.2.2     
[16] rstudioapi_0.10     minqa_1.2.4         data.table_1.12.8  
[19] nloptr_1.2.1        rpart_4.1-15        Matrix_1.2-17      
[22] checkmate_1.9.4     splines_3.6.1       lme4_1.1-21        
[25] stringr_1.4.0       foreign_0.8-71      htmlwidgets_1.5.1  
[28] munsell_0.5.0       broom_0.5.2         compiler_3.6.1     
[31] xfun_0.10           pkgconfig_2.0.3     base64enc_0.1-3    
[34] htmltools_0.4.0     nnet_7.3-12         tidyselect_0.2.5   
[37] tibble_2.1.3        htmlTable_1.13.2    crayon_1.3.4       
[40] withr_2.1.2         MASS_7.3-51.4       nlme_3.1-140       
[43] gtable_0.3.0        lifecycle_0.1.0     scales_1.0.0       
[46] stringi_1.4.3       latticeExtra_0.6-28 generics_0.0.2     
[49] vctrs_0.2.0         boot_1.3-22         prediction_0.3.14  
[52] RColorBrewer_1.1-2  tools_3.6.1         glue_1.3.1         
[55] purrr_0.3.2         parallel_3.6.1      colorspace_1.4-1   
[58] cluster_2.1.0       knitr_1.25         
